package com.night.icm.controller.business;

import com.night.icm.common.utils.PageDataDTO;
import com.night.icm.model.business.ConsolidatedResultsDTO;
import com.night.icm.model.business.DataSeriesDTO;
import com.night.icm.service.business.service.StatisticalAnalysisService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import java.util.List;

/**
 * StatisticalAnalysisController
 *
 * @author Liao ZhiYong
 * @date 2020/4/1
 */
@Api(tags = "统计与分析")
@RestController
@RequestMapping("/api/icm-statistical-analysis")
public class StatisticalAnalysisController {

    private final StatisticalAnalysisService statisticalAnalysisService;

    @Autowired
    public StatisticalAnalysisController(StatisticalAnalysisService statisticalAnalysisService) {
        this.statisticalAnalysisService = statisticalAnalysisService;
    }

    @ApiOperation(value = "分页查找学生综合成绩列表")
    @GetMapping(value = "")
    public PageDataDTO<ConsolidatedResultsDTO> findOnePage(
            @ApiParam(value = "页号，从0开始", required = true, defaultValue = "0") @RequestParam("page") @Min(0) int page,
            @ApiParam(value = "每页记录条数", required = true, defaultValue = "30") @RequestParam("size") @Min(1) @Max(100) int size,
            @ApiParam(value = "排序字段，例如：字段1,asc,字段2,desc") @RequestParam(value = "sort", required = false, defaultValue = "id,desc") String sort,
            @ApiParam(value = "学院名称") @RequestParam(value = "academyId", required = false) String academyId,
            @ApiParam(value = "专业名称") @RequestParam(value = "professionId", required = false) String professionId,
            @ApiParam(value = "班级名称") @RequestParam(value = "classId", required = false) String classId,
            @ApiParam(value = "学生姓名") @RequestParam(value = "studentName", required = false) String studentName,
            @ApiParam(value = "测评年份") @RequestParam(value = "year", required = false) String year
    ) {
        return this.statisticalAnalysisService.findOnePage(page, size, sort, academyId, professionId, classId, studentName, year);
    }

    /**
     * 按学院、专业、班级、学年分别统计
     * 综合成绩达标、不达标、预警的学生数量
     */
    @ApiOperation(value = "统计与分析学生综合成绩情况")
    @GetMapping(value = "/consolidated-results/count")
    public List<DataSeriesDTO> analysisConsolidatedResults(
            @ApiParam(value = "测评年份", required = true) @RequestParam(value = "year") String year,
            @ApiParam(value = "达标分数", required = true) @RequestParam(value = "standard") Double standard,
            @ApiParam(value = "未达标分数", required = true) @RequestParam(value = "notStandard") Double notStandard,
            @ApiParam(value = "预警下限", required = true) @RequestParam(value = "earlyWarningDown") Double earlyWarningDown,
            @ApiParam(value = "预警上限", required = true) @RequestParam(value = "earlyWarningUp") Double earlyWarningUp,
            @ApiParam(value = "学院名称") @RequestParam(value = "academyId", required = false) String academyId,
            @ApiParam(value = "专业名称") @RequestParam(value = "professionId", required = false) String professionId,
            @ApiParam(value = "班级名称") @RequestParam(value = "classId", required = false) String classId
    ) {
        return this.statisticalAnalysisService.analysisConsolidatedResults(academyId, professionId, classId, year, standard, notStandard, earlyWarningDown, earlyWarningUp);
    }

    /**
     * 按学院、专业、班级分别统计当前学年
     * 每个年级学生的合计毕业所需学分达标、不达标、预警的学生数量
     * 年级选择取当前年份及前3年
     */
    @ApiOperation(value = "统计与分析毕业学分修读情况")
    @GetMapping(value = "/graduation-credits/count")
    public List<DataSeriesDTO> analysisGraduationCredits(
            @ApiParam(value = "达标分数", required = true) @RequestParam(value = "standard") Double standard,
            @ApiParam(value = "未达标分数", required = true) @RequestParam(value = "notStandard") Double notStandard,
            @ApiParam(value = "预警下限", required = true) @RequestParam(value = "earlyWarningDown") Double earlyWarningDown,
            @ApiParam(value = "预警上限", required = true) @RequestParam(value = "earlyWarningUp") Double earlyWarningUp,
            @ApiParam(value = "学院名称") @RequestParam(value = "academyId", required = false) String academyId,
            @ApiParam(value = "专业名称") @RequestParam(value = "professionId", required = false) String professionId,
            @ApiParam(value = "班级名称") @RequestParam(value = "classId", required = false) String classId,
            @ApiParam(value = "所属年级") @RequestParam(value = "grade", required = false) String grade
    ) {
        return this.statisticalAnalysisService.analysisGraduationCredits(academyId, professionId, classId, grade, standard, notStandard, earlyWarningDown, earlyWarningUp);
    }

}